<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const createGenerator1 = function * (){
            yield 'success1'
            yield 'success2'
            yield 'success3'
        }
        const createGenerator2 = async function * (){
            yield await new Promise((r) => r('success1'))
            yield 'success2'
            yield 'success3'
        }
        const main1 = () => {
            const generator = createGenerator1()
            for (const item of generator){
                console.log(item)
                
            }
            console.log('generator',generator[Symbol.iterator])
            console.log('generator',generator.next())
        }
        main1()
        //异步可迭代的
        //怎么遍历一个不可迭代的但是可以异步迭代的对象
        const main2 = () => {
            const asyncgenerator = createGenerator2()
            console.log('asyncgenerator',asyncgenerator[Symbol.iterator])
            console.log('asyncgenerator',asyncgenerator.next())
            console.log('asyncgenerator',asyncgenerator)
            for await(const item of generator){
                console.log(item)
            }
        }
        main2()

    </script>
</body>
</html>